package com.uplift.mobile.user.controller;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.uplift.common.result.IResultable;
import com.uplift.common.result.ResultWrapper;
import com.uplift.mobile.user.model.Receipts;
import com.uplift.mobile.user.service.IReceiptsService;

/**
 * 收款记录
 * 
 * @author bcwang
 *
 */
@Controller
@RequestMapping(value = "/receipts")
public class ReceiptsController {

	@Autowired
	private IReceiptsService receiptsService;

	/**
	 * 查询收款记录
	 * 
	 * @param request
	 * @param receipts
	 * @return IResultable
	 */
	@RequestMapping(value = "/list")
	@ResponseBody
	public IResultable list(HttpServletRequest request, Receipts receipts) {
		try {
			List<Map<String, Object>> list = this.receiptsService.queryReceipts(receipts);
			return ResultWrapper.wrapListPage(list, ResultWrapper.SUCC, "查询成功");
		} catch (Exception e) {
			e.printStackTrace();
			return ResultWrapper.wrapListPage(null, ResultWrapper.FAIL, "查询失败");
		}
	}

	/**
	 * 查询收款总金额
	 * 
	 * @param request
	 * @param receipts
	 * @return IResultable
	 */
	@RequestMapping(value = "/total")
	@ResponseBody
	public IResultable total(HttpServletRequest request, Receipts receipts) {
		try {
			Map<String, Object> map = this.receiptsService.queryReceiptsTotal(receipts);
			return ResultWrapper.wrapMap(map, ResultWrapper.SUCC, "查询成功");
		} catch (Exception e) {
			e.printStackTrace();
			return ResultWrapper.wrapMap(null, ResultWrapper.FAIL, "查询失败");
		}
	}	
}
